{% extends 'base.html' %}
{% load crispy_forms_filters %}
{% load crispy_forms_tags %}

{% block title %}个人资料 - 个人博客{% endblock %}

{% block content %}
<div class="container">
    <div class="row">
        <!-- 个人资料 -->
        <div class="col-lg-4 mb-4">
            <div class="card shadow-sm">
                <div class="card-header bg-light">
                    <h2 class="mb-0">个人资料</h2>
                </div>
                <div class="card-body">
                    <div class="text-center mb-4">
                        {% if user.avatar %}
                        <img src="{{ user.avatar.url }}" alt="{{ user.username }}" class="rounded-circle img-fluid mb-3" style="max-width: 150px;">
                        {% else %}
                        <img src="https://via.placeholder.com/150" alt="{{ user.username }}" class="rounded-circle img-fluid mb-3">
                        {% endif %}
                        <h3>{{ user.username }}</h3>
                        <p class="text-muted">{{ user.email }}</p>
                    </div>
                    
                    <form method="post" enctype="multipart/form-data">
                        {% csrf_token %}
                        {{ form|crispy }}
                        <button type="submit" class="btn btn-primary w-100 mt-3">更新资料</button>
                    </form>
                </div>
            </div>
        </div>
        
        <!-- 我的文章 -->
        <div class="col-lg-8">
            <div class="card shadow-sm">
                <div class="card-header bg-light d-flex justify-content-between align-items-center">
                    <h2 class="mb-0">我的文章</h2>
                    <a href="{% url 'post_create' %}" class="btn btn-primary">
                        <i class="fas fa-plus me-1"></i> 写新文章
                    </a>
                </div>
                <div class="card-body">
                    <div class="table-responsive">
                        <table class="table table-hover">
                            <thead>
                                <tr>
                                    <th>标题</th>
                                    <th>状态</th>
                                    <th>发布时间</th>
                                    <th>浏览量</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                {% for post in user_posts %}
                                <tr>
                                    <td>
                                        <a href="{{ post.get_absolute_url }}" class="text-decoration-none">{{ post.title }}</a>
                                    </td>
                                    <td>
                                        {% if post.status == 'published' %}
                                        <span class="badge bg-success">已发布</span>
                                        {% elif post.status == 'draft' %}
                                        <span class="badge bg-secondary">草稿</span>
                                        {% elif post.status == 'scheduled' %}
                                        <span class="badge bg-warning">定时发布</span>
                                        {% endif %}
                                    </td>
                                    <td>{{ post.publish_date|date:"Y-m-d H:i" }}</td>
                                    <td>{{ post.views }}</td>
                                    <td>
                                        <div class="btn-group btn-group-sm">
                                            <a href="{% url 'post_edit' post.pk %}" class="btn btn-outline-primary">
                                                <i class="fas fa-edit"></i>
                                            </a>
                                            <a href="{% url 'post_delete' post.pk %}" class="btn btn-outline-danger">
                                                <i class="fas fa-trash"></i>
                                            </a>
                                        </div>
                                    </td>
                                </tr>
                                {% empty %}
                                <tr>
                                    <td colspan="5" class="text-center">你还没有发布任何文章</td>
                                </tr>
                                {% endfor %}
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}

